<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>商品分类管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			if(${productClassify.id!=null && productClassify.id!=''} && $("input[name='level']:checked").val()=="1"){
				$("#level2").attr("disabled", true);
			}
			$("#name").focus();
			$("#inputForm").validate({
				rules: {
					name: {remote: "${ctx}/ivm/product/classify/checkName?oldName="+encodeURIComponent('${productClassify.name}')}
				},
				messages: {
					name: {remote: "商品分类已存在"}
				},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			//加载处理level选择控制
			changeLevel($("input[name='level']:checked"));
			
			// 定义一个新的复制对象
			var clip = new ZeroClipboard($("a[id='clip_button']"), {
			  moviePath: "${ctxStatic }/ZeroClipboard/ZeroClipboard.swf"
			} );
			
			// 复制内容到剪贴板成功后的操作
			clip.on( 'complete', function(client, args) {
			   alert("复制成功，请到剪贴板粘帖！");
			} );
		});
		
		function changeLevel(obj){
			if($(obj).val()=='1'){
				$("#parent").val("");
				$("select").select2();
				$(".level-select").hide();
			}else{
				$(".level-select").show();
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/ivm/product/classify/list">分类列表</a></li>
		<li class="active"><a href="${ctx}/ivm/product/classify/form?id=${productClassify.id}">分类<shiro:hasPermission name="ivm:product:classify:edit">${not empty productClassify.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="ivm:product:classify:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="productClassify" action="${ctx}/ivm/product/classify/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="merchant.id"/>
		<tags:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>分类级别:</label>
			<div class="controls">
				<form:radiobuttons path="level" onchange="changeLevel(this)" items="${fns:getDictList('pro_classify')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required" />
			</div>
		</div>
		<div class="control-group level-select">
			<label class="control-label"><span class="color-red font-size20">*</span>一级分类:</label>
			<div class="controls">
				<form:select id="parent" path="parent.id" class="required">
					<form:option value="" label="请选择"/>
					<form:options items="${fns:getClassifyOneList()}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20">*</span>名称:</label>
			<div class="controls">
				<input id="oldName" name="oldName" type="hidden" value="${productClassify.name}">
				<form:input path="name" htmlEscape="false" maxlength="200" class="required name"/>
			</div>
		</div>
		<c:if test="${productClassify.id!=null && productClassify.id!='' && productClassify.level=='1'}">
		<div class="control-group">
			<label class="control-label"><span class="color-red font-size20"></span>链接:</label>
			<div class="controls">
				<form:input path="shopUrl" htmlEscape="false" maxlength="200" readonly="true" style="width: 400px;"/>
				<a href="javascript:" class="btn" id="clip_button" data-clipboard-target="shopUrl">复制</a>
			</div>
		</div>
		</c:if>
		<div class="control-group">
			<label class="control-label">备注:</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="200" class="input-xxlarge"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="ivm:product:classify:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>
